package com.linpq.road.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.linpq.common.annotation.Log;
import com.linpq.common.enums.BusinessType;
import com.linpq.road.domain.RoadInformation;
import com.linpq.road.service.RoadInformationService;
import com.linpq.common.core.controller.BaseController;
import com.linpq.common.core.domain.AjaxResult;
import com.linpq.common.utils.poi.ExcelUtil;
import com.linpq.common.core.page.TableDataInfo;

/**
 * 道路基本信息Controller
 *
 * @author linpq
 * @date 2021-02-10
 */
@Controller
@RequestMapping("/road/information")
public class RoadInformationController extends BaseController {
    private String prefix = "road/information";

    @Autowired
    private RoadInformationService roadInformationService;

    @RequiresPermissions("road:information:view")
    @GetMapping()
    public String information() {
        return prefix + "/information";
    }

    /**
     * 查询道路基本信息列表
     */
    @RequiresPermissions("road:information:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RoadInformation roadInformation) {
        startPage();
        List<RoadInformation> list = roadInformationService.selectRoadInformationList(roadInformation);
        return getDataTable(list);
    }

    /**
     * 导出道路基本信息列表
     */
    @RequiresPermissions("road:information:export")
    @Log(title = "道路基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RoadInformation roadInformation) {
        List<RoadInformation> list = roadInformationService.selectRoadInformationList(roadInformation);
        ExcelUtil<RoadInformation> util = new ExcelUtil<RoadInformation>(RoadInformation. class);
        return util.exportExcel(list, "information");
    }

    /**
     * 新增道路基本信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存道路基本信息
     */
    @RequiresPermissions("road:information:add")
    @Log(title = "道路基本信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RoadInformation roadInformation) {
        return toAjax(roadInformationService.insertRoadInformation(roadInformation));
    }

    /**
     * 修改道路基本信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        RoadInformation roadInformation =roadInformationService.selectRoadInformationById(id);
        mmap.put("roadInformation", roadInformation);
        return prefix + "/edit";
    }

    /**
     * 修改保存道路基本信息
     */
    @RequiresPermissions("road:information:edit")
    @Log(title = "道路基本信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RoadInformation roadInformation) {
        return toAjax(roadInformationService.updateRoadInformation(roadInformation));
    }

    /**
     * 删除道路基本信息
     */
    @RequiresPermissions("road:information:remove")
    @Log(title = "道路基本信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(roadInformationService.deleteRoadInformationByIds(ids));
    }
}
